package com.quectel.business.common.partybuilding;

import com.quectel.business.common.util.sys.SysCodeUtils;
import com.quectel.constant.sys.SysCodeKeyConstants;
import com.quectel.core.module.partybuilding.dto.PartyOrganizationDto;
import com.quectel.core.module.partybuilding.service.PartyOrganizationService;
import com.quectel.core.module.partybuilding.service.PartyPersonService;
import com.quectel.core.module.partybuildingmeeting.dto.PartyBuildingMeetingDto;
import com.quectel.sys.module.sys.dto.SysCodeDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

/**
 * 在这里编写说明
 *
 * @author: bob
 * @email: bob.yu@quectel.com
 * @date: 2023-06-06 18:54:00
 */
@Component
@Slf4j
public class PartyPersonBusiness {

    @DubboReference
    private PartyOrganizationService partyOrganizationService;
    @DubboReference
    private PartyPersonService partyPersonService;

    /**
     * 获取权限下的党组织ids
     * @param partyId
     * @return
     */
    public Long[] getPartyIds(Long partyId) {
        List<PartyOrganizationDto> recursion = partyOrganizationService.recursion(partyId);
        if (CollectionUtils.isNotEmpty(recursion)) {
            return recursion.stream().map(PartyOrganizationDto::getId).toArray(Long[]::new);
        } else {
            return new Long[0];
        }
    }

    /**
     *
     */
    public String[] getCategoryAndType(PartyBuildingMeetingDto subjectDto) {
        String categoryName = "";
        String groupTypeName = "";
        List<SysCodeDto> subjectCategory = SysCodeUtils.easyToGetByMark(SysCodeKeyConstants.PARTY_BUILDING_MEETING);
        if (subjectCategory != null) {
            for (SysCodeDto sysCodeDto : subjectCategory) {
                if (Objects.equals(subjectDto.getCategory() + "", sysCodeDto.getValue())) {
                    categoryName = sysCodeDto.getName();
                    List<SysCodeDto> children = sysCodeDto.getChildren();
                    if (children != null) {
                        for (SysCodeDto child : children) {
                            if (Objects.equals(child.getValue(), subjectDto.getType() + "")) {
                                groupTypeName = child.getName();
                                break;
                            }
                        }
                    }
                    break;
                }
            }
        }
        return new String[]{categoryName, groupTypeName};
    }


}
